﻿package modular.module {
	import flash.display.MovieClip;
	
	import modular.ModuleInfo;
	import modular.ModuleSet;
	import modular.events.ModuleEvent;	

	/**
	 * @author mich
	 */
	public class Module extends MovieClip {

		private var _info:ModuleInfo;

		public function Module() {
			super();
		}

		
		public function show():void {
			if( info.parentLoader != null ) info.parentLoader.addChild( this );
		}

		
		public function hide():void {
			if( parent != null ) parent.removeChild( this);
		}
		
		protected function adjustPosition( xpos:Number, ypos:Number ):void {
			if( !isNaN( xpos ) ) this.x = xpos;
			if( !isNaN( ypos ) ) this.y = ypos;
		}
		
		protected function adjustSize( w:Number, h:Number ):void {
			if( !isNaN( w ) ) this.width = w;
			if( !isNaN( h ) ) this.height = h;
		}

		
		public function set info( mi:ModuleInfo ):void {
			_info = mi;
			adjustPosition( _info.position.x, _info.position.y );
			adjustSize( _info.width, _info.height );
			dispatchEvent( new ModuleEvent( ModuleEvent.INFO_CHANGED ) );
		}
		
		public function get info():ModuleInfo {
			return _info;
		}
		
		public function destroy():void {
			_info.destroy();
			_info = null;
		}
	}
}
